﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace octopus_project.input {

    enum ActionKey {
        UP,
        DOWN,
        LEFT,
        RIGHT,
        FIRE,
        ROTATE,
        CONFIRM,
        CANCEL,
        SKIP_SCENE
    }

    static class KeyMap {

        public static Dictionary<ActionKey, Keys> generalKeys;

        public static Dictionary<ActionKey, Keys> playerOneKeys;
        public static Dictionary<ActionKey, Buttons> playerOneButtons;

        public static Dictionary<ActionKey, Keys> playerTwoKeys;
        public static Dictionary<ActionKey, Buttons> playerTwoButtons;

        public static Dictionary<ActionKey, Keys> playerThreeKeys;
        public static Dictionary<ActionKey, Buttons> playerThreeButtons;

        public static Dictionary<ActionKey, Keys> playerFourKeys;
        public static Dictionary<ActionKey, Buttons> playerFourButtons;


        static KeyMap() {
            initGeneralKeyMap();
            initPlayerOneKeyMap();
            initPlayerTwoKeyMap();
            initPlayerThreeKeyMap();
            initPlayerFourKeyMap();
        }

        private static void initGeneralKeyMap () {
            generalKeys = new Dictionary<ActionKey, Keys>();

            generalKeys.Add(ActionKey.CONFIRM, Keys.Enter);
            generalKeys.Add(ActionKey.CANCEL, Keys.Escape);
            generalKeys.Add(ActionKey.SKIP_SCENE, Keys.Tab);
        }

        private static void initPlayerOneKeyMap () {
            playerOneKeys = new Dictionary<ActionKey, Keys>();
            playerOneButtons = new Dictionary<ActionKey, Buttons>();

            playerOneKeys.Add(ActionKey.UP, Keys.Up);
            playerOneKeys.Add(ActionKey.DOWN, Keys.Down);
            playerOneKeys.Add(ActionKey.LEFT, Keys.Left);
            playerOneKeys.Add(ActionKey.RIGHT, Keys.Right);
            playerOneKeys.Add(ActionKey.FIRE, Keys.OemCloseBrackets);
            playerOneKeys.Add(ActionKey.ROTATE, Keys.OemOpenBrackets);

        }

        private static void initPlayerTwoKeyMap () {
            playerTwoKeys = new Dictionary<ActionKey, Keys>();
            playerTwoButtons = new Dictionary<ActionKey, Buttons>();

            playerTwoKeys.Add(ActionKey.UP, Keys.E);
            playerTwoKeys.Add(ActionKey.DOWN, Keys.D);
            playerTwoKeys.Add(ActionKey.LEFT, Keys.S);
            playerTwoKeys.Add(ActionKey.RIGHT, Keys.F);
            playerTwoKeys.Add(ActionKey.FIRE, Keys.W);
            playerTwoKeys.Add(ActionKey.ROTATE, Keys.Q);
        }

        private static void initPlayerThreeKeyMap () {
            playerThreeKeys = new Dictionary<ActionKey, Keys>();
            playerThreeButtons = new Dictionary<ActionKey, Buttons>();

            playerThreeButtons.Add(ActionKey.UP, Buttons.DPadUp);
            playerThreeButtons.Add(ActionKey.DOWN, Buttons.DPadDown);
            playerThreeButtons.Add(ActionKey.LEFT, Buttons.DPadLeft);
            playerThreeButtons.Add(ActionKey.RIGHT, Buttons.DPadRight);
            playerThreeButtons.Add(ActionKey.FIRE, Buttons.A);
            playerThreeButtons.Add(ActionKey.ROTATE, Buttons.B);

        }

        private static void initPlayerFourKeyMap () {
            playerFourKeys = new Dictionary<ActionKey, Keys>();
            playerFourButtons = new Dictionary<ActionKey, Buttons>();

            playerFourKeys.Add(ActionKey.UP, Keys.Y);
            playerFourKeys.Add(ActionKey.DOWN, Keys.H);
            playerFourKeys.Add(ActionKey.LEFT, Keys.G);
            playerFourKeys.Add(ActionKey.RIGHT, Keys.J);
            playerFourKeys.Add(ActionKey.FIRE, Keys.T);
            playerFourKeys.Add(ActionKey.ROTATE, Keys.R);

        }

        /// <summary>
        /// Description.
        /// </summary>
        public static Keys getGeneralActionKey (ActionKey actionKey) {
            if(generalKeys.ContainsKey(actionKey)) {
                return generalKeys[actionKey];
            }
            else {
                return Keys.None;
            }
        }


    }
}
